import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import actions from './actions'
import getters from './getters'
//1.安装插件
Vue.use(Vuex)


//2.创建Store对象
const state = {

  cartList:[]
}
const store = new Vuex.Store({
  state,
  mutations,
  getters,
/*  mutations:{
     //addCart(state,payload) {
       /!*let oldProduct = null
       //值得注意的是of是当前加1
       for(let item of state.cartList){
         if(item.id === payload.id){
           oldProduct = item
         }
       }*!/
//还有就是mutation里的函数应该是比较单一的逻辑函数，涉及到判断的函数应该用actions
/!*       if(oldProduct){
         oldProduct.count +=1
       }else {
         payload.count = 1
         state.cartList.push(payload)
       }*!/

    // }
    //数量加1

  },*/
actions
/*  actions: {

      /!*addCart(context, payload){
        let index = context.state.cartList.indexOf(payload)
      //2.判断oldProduct
      if (index !== -1) {
        let oldProduct = context.state.cartList[index]
        //oldProduct.count += 1
        context.commit("addCounter",oldProduct)
      } else {
        payload.count = 1
        //context.state.cartList.push(payload)
        context.commit('addCartM',payload)
      }*!/

  }*/
})

//3.挂载Vue实例上
export default  store
